//
//  AppDelegate.m
//  XHAdSDKTest
//
//  Created by 陈俭红 on 2022/1/5.
//

#import "AppDelegate.h"
//M
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
//C
#import "ViewController.h"
//
#import <XHAdSDK/XHAdSDK.h>

@interface AppDelegate ()<XHSplashAdDelegate>

/* <#name#> */
@property (nonatomic, strong) XHAdCenter *center;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //设置window
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    
    //设置VC
    ViewController * vc = [ViewController new];
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nav;
    
    __weak __typeof(&*self)weakSelf = self;
    //初始化广告
    [XHAdSDKManager initWithAppId:@"248199192290263105" success:^{
        //初始化开屏--(可选)
        [XHAdSDKManager initSplashWithAppId:@"248499608345378912" success:^{
            [weakSelf playBtnAction];
        } failure:^{
            
        }];
    } failure:^{
        
    }];
    //初始化激励视频--(可选)
    [XHAdSDKManager initRewardAdWithAppId:@"248200204069634093" success:^{
        
    } failure:^{
        
    }];
    //初始化插页--(可选)
    [XHAdSDKManager initInterAdWithAppId:@"248575688326512648" success:^{
        
    } failure:^{
        
    }];
    //初始化banner--(可选)
    [XHAdSDKManager initBannerAdWithAppId:@"248199686639321121" success:^{
        
    } failure:^{
        
    }];
    //初始化信息流--(可选)
    [XHAdSDKManager initFeedAdWithAppId:@"289121257167781981" success:^{
        
    } failure:^{
        
    }];
    //初始化信息流--(可选)
    [XHAdSDKManager initFeedAdWithAppId:@"356804558841708641" success:^{
        
    } failure:^{
        
    }];
    //初始化Draw--(可选)
    [XHAdSDKManager initDrawAdWithAppId:@"289150002507284541" success:^{
        
    } failure:^{
        
    }];
    
    [self requestIDFA];
    
    return YES;
}

- (void)playBtnAction{
    XHAdCenter * center = [XHAdCenter new];
    XHSplashAdData * data = [XHSplashAdData new];
    data.splashDelegate = self;
    data.timeoutInterval = 3;
    data.isPreload = YES;   //是否预加载 默认NO
    [center xh_showSplashAd:data];
    self.center = center;
    
}

- (void)xh_onSplashAdDidLoad {
    NSLog(@"广告预加载成功");
    [self.center xh_showPreloadSplashAd];
}

/** 广告加载失败，msg加载失败说明（如果重新请求广告，注意：只重新请求一次）*/
- (void)xh_onSplashAdFail:(NSString *)errorString{
    
}

/** 广告渲染成功 */
- (void)xh_onSplashAdExposure{
    
}

/** 广告被点击 */
- (void)xh_onSplashAdClicked{
    
}

/** 广告被跳过 */
- (void)xh_onSplashAdClose{
    
}

/** 广告结束(跳过或者倒计时结束调用) */
- (void)xh_onSplashAdFinish {
    NSLog(@"广告结束 ====");
}

//MARK: 请求IDFA
- (void)requestIDFA{
    if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            
        }];
    }
}
@end
